package com.controller;

import com.pojo.Post;
import com.service.PostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/org/post")
public class PostController {
    @Autowired
    private PostService postService;
    /**
     * 添加部门
     */
    @PostMapping
    public String addPost(@RequestBody Post post){
        return  postService.addPost(post)>0 ? "操作成功" :"操作失败";
    }
    /**
     *  查询所有部门
     */
    @GetMapping
    public List<Post> selectAllPost(){
        return  postService.selectAllPost();
    }

    /**
     * 根据条件查询
     */
    @GetMapping("/{postName}/{postCode}/{postStatus")
    public  List<Post> selectPostByCondition(@PathVariable String postName,@PathVariable String postCode,@PathVariable Integer postStatus){
        Post post = new Post();
        post.setP_name(postName);
        post.setP_encode(postCode);
        post.setP_statu(postStatus);
        return  postService.selectPostByCondition(post);
    }
    /**
     * 修改信息
     */
    @PutMapping
    public String updatePost(@RequestBody Post post){
        return  postService.updatePost(post)>0 ? "操作成功" :"操作失败";
    }
    /**
     * 删除信息
     */
    @DeleteMapping("/{postName}")
    public  String deletePost(@PathVariable String postName){
        return  postService.deletePost(postName)>0 ? "操作成功" :"操作失败";
    }
}
